package com.abc.scholarship.service.impl;

import com.abc.scholarship.domain.entity.Clazz;
import com.abc.scholarship.domain.entity.MajorGradeNum;
import com.abc.scholarship.mapper.MajorGradeNumMapper;
import com.abc.scholarship.service.MajorGradeNumService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;

/**
 * @Author: LiJunXi
 * @Description:
 * @Date: 2024-07-04  11:55
 */
@Service
public class MajorGradeNumServiceImpl extends ServiceImpl<MajorGradeNumMapper, MajorGradeNum> implements MajorGradeNumService {

    @Autowired
    private MajorGradeNumMapper majorGradeNumMapper;

    @Override
    public void addStuNum(String majorGrade) {
        lambdaUpdate()
                .setSql("num = num + 1")
                .eq(MajorGradeNum::getMajorGrade, majorGrade)
                .update();
    }

    @Override
    public List<MajorGradeNum> getNotExitByNames(List<String> names) {
        Set<String> collect = majorGradeNumMapper.selectList(new LambdaQueryWrapper<MajorGradeNum>()
                .select(MajorGradeNum::getMajorGrade)
                .in(MajorGradeNum::getMajorGrade, names)
        ).stream().map(MajorGradeNum::getMajorGrade).collect(Collectors.toSet());

        return new ArrayList<>(
                names.stream()
                        .filter(item -> !collect.contains(item))
                        .map(MajorGradeNum::new)
                        .collect(Collectors.toSet())
        );
    }
}
